package com.funteam.globalalarm;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.provider.MediaStore.Audio;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {
	
	private int APP_NOTIFICATION_ID;
	
	@Override
	public void onReceive(Context context, Intent intent) {
		Toast.makeText(context, R.string.app_name, Toast.LENGTH_SHORT).show();
		
		showNotification(context, R.drawable.earth, "Alarm!!", "Hurry up!!");
	}

	private void showNotification(Context context, int statusBarIconID, String statusBarTextID, String detailedTextID) {
		Intent contentIntent = new Intent(context, TestPageWrite.class);
		PendingIntent theappIntent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
		
		CharSequence from = "Alarm";
		CharSequence message = "You need to do something for finishing this alarm.";
		
		Notification notif = new Notification(statusBarIconID, null, System.currentTimeMillis());
		notif.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");			// ring URI
		notif.flags = Notification.FLAG_INSISTENT;
		notif.setLatestEventInfo(context, from, message, theappIntent);
		notif.ledARGB = Color.GREEN;
		NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
		
		// cancel notification
		nm.cancel(1234);
		//finish();
		//nm.notify(1234, notif);
	}
}
